/**
 * 
 */
package com.yst.metho.web.application.components;

import nextapp.echo2.app.Button;
import nextapp.echo2.app.Component;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Row;
import nextapp.echo2.app.SplitPane;
import nextapp.echo2.app.WindowPane;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;
import nextapp.echo2.app.event.WindowPaneEvent;
import nextapp.echo2.app.event.WindowPaneListener;

import com.yst.metho.web.application.utils.Styles;

/**
 * Fenetre qui permet d'editer des objets generiques qui se basent sur une
 * definition et une valeur.
 * 
 * @author perso
 * 
 */
public class MessagePopupWindow extends WindowPane
{

	private static final String CONTROL_PANE_BUTTON_STYLE = "ControlPane.Button";

	private static final int POPUP_WINDOW_TITLE_HEIGHT = 52;

	private static final int CONTROL_PANE_HEIGHT = 32;

	private static final int POPUP_HEIGHT = 400;

	private static final int POPUP_WIDTH = 400;

	private static final String POPUP_WINDOW_STYLE = "Default";

	private Component mComponentView;

	private SplitPane mMainSplitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL);

	private Button mBtnCancel;


	public MessagePopupWindow(Component objdef, String title)
	{
		super(title, new Extent(POPUP_WIDTH, Extent.PX), new Extent(POPUP_HEIGHT, Extent.PX));
		mComponentView = objdef;
		setResizable(false);
		setDefaultCloseOperation(WindowPane.DO_NOTHING_ON_CLOSE);
		setStyleName(POPUP_WINDOW_STYLE);
		setModal(true);
		addWindowPaneListener(new WindowPaneListener()
		{
			public void windowPaneClosing(WindowPaneEvent e)
			{
				cancel();
			}
		});
		mMainSplitPane.setSeparatorPosition(new Extent(POPUP_HEIGHT - CONTROL_PANE_HEIGHT - POPUP_WINDOW_TITLE_HEIGHT, Extent.PX));
		mMainSplitPane.setStyleName(Styles.FIXED_SPLIT_PANE_STYLE);
		add(mMainSplitPane);
		// consruction de la zone d'information
		mMainSplitPane.add(mComponentView);

		// construction de la zone de controle
		Row controlPane = new Row();
		controlPane.setStyleName("ControlPane");
		mBtnCancel = new Button("Ok");
		mBtnCancel.setStyleName(CONTROL_PANE_BUTTON_STYLE);
		mBtnCancel.addActionListener(new ActionListener()
		{

			public void actionPerformed(ActionEvent e)
			{
				cancel();
			}
		});
		controlPane.add(mBtnCancel);
		mMainSplitPane.add(controlPane);
	}

	/**
	 * Annule toutes les modifications et ferme la fenetre.
	 * 
	 */
	private void cancel()
	{
		getParent().remove(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see nextapp.echo2.app.WindowPane#setHeight(nextapp.echo2.app.Extent)
	 */
	public void setHeight(Extent taille)
	{
		super.setHeight(taille);
		if (null != mMainSplitPane)
		{
			mMainSplitPane.setSeparatorPosition(new Extent(taille.getValue() - CONTROL_PANE_HEIGHT - POPUP_WINDOW_TITLE_HEIGHT, Extent.PX));
		}
	}

	/**
	 * @param cancelMsg the cancelMsg to set
	 */
	public void setCancelMsg(String cancelMsg)
	{
		mBtnCancel.setText(cancelMsg);
	}
}
